<?php
/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 14-10-17
 * Time: 下午2:04
 */

class ComplexService extends Service {
	
	public static function channelSumHeader(){
		$MainData =array(
				'RegUser'       => array('text' => '新注册账号数', 'rule' => 'numeric'),
				'RoleUser'      => array('text' => '创角数', 'rule' => 'numeric'),
				'DAU'           => array('text' => '活跃人数', 'rule' => 'numeric'),
				'LoginUser'     => array('text' => '登入人数', 'rule' => 'numeric'),
				'LogoutUser'    => array('text' => '登出人数', 'rule' => 'numeric'),
				'OldUser'       => array('text' => '老用户数', 'rule' => 'numeric'),
				'LoginCount'    => array('text' => '登录次数', 'rule' => 'numeric'),
				'PayUser'       => array('text' => '充值玩家数', 'rule' => 'numeric'),
				'PayMoney'      => array('text' => '充值收入', 'rule' => 'numeric'),
				'PayCount'      => array('text' => '充值次数', 'rule' => 'numeric'),
				'PayGold'       => array('text' => '充值所得元宝数', 'rule' => 'numeric'),
				'PresentGold'   => array('text' => '充值赠送元宝数', 'rule' => 'numeric'),
				'UsedGold'      => array('text' => '消耗虚拟货币数', 'rule' => 'numeric'),
		);
		$FirstData = array(
				'FirstPayUser'  => array('text' => '首充玩家数', 'rule' => 'numeric'),
				'FirstPayCount' => array('text' => '首充订单数', 'rule' => 'numeric'),
				'FirstPayMoney' => array('text' => '首充金额', 'rule' => 'numeric'),
				'FirstPayGold'  => array('text' => '首充元宝数', 'rule' => 'numeric'),
		);
		$CumData = array(
				'CumRegUser'    => array('text' => '累计注册账号', 'rule' => 'numeric'),
				'CumRoleUser'   => array('text' => '累计创角数', 'rule' => 'numeric'),
		);
		$MainArppu = array(
			'arppu' => array('text' => 'arppu'),
			'loginArppu' => array('text' => '登录付费率'),
			'addPayArppu' => array('text' => '新增付费率'),
			'addArppu' => array('text' => '新增arppu'),
		);
		
		$oneHeader = array(
				'RecDate'   => array('text' => '日期'),
				'Special'   => array('text' => PubFunc::t('专服')),
				'MainData'  => array('text' => '核心数据', 'include' => $MainData),
				'FirstData'     => array('text' => '首充数据', 'include' => $FirstData),
				'CumData'       => array('text' => '累计数据', 'include' => $CumData),
				'MainArppu' => array('text' => '付费率', 'include' => $MainArppu),
		);
		$twoHeader = array(
				'RecDate'   => array('text' => '日期'),
				'Special'   => array('text' => PubFunc::t('专服')),
				'MainData'  => array('text' => '核心数据', 'include' => $MainData),
				'FirstData'     => array('text' => '首充数据', 'include' => $FirstData),
				'CumData'       => array('text' => '累计数据', 'include' => $CumData),
				'MainArppu' => array('text' => '付费率', 'include' => $MainArppu),
		);
		$threeHeader = array(
				'RecDate'   => array('text' => '日期'),
				'Special'   => array('text' => PubFunc::t('专服')),
				'Channel'   => array('text' => PubFunc::t('渠道')),
				'MainData'  => array('text' => '核心数据', 'include' => $MainData),
				'FirstData'     => array('text' => '首充数据', 'include' => $FirstData),
				'CumData'       => array('text' => '累计数据', 'include' => $CumData),
				'MainArppu' => array('text' => '付费率', 'include' => $MainArppu),
		);
		
		return array(
				'one'   =>  $oneHeader,
				'two'  =>  $twoHeader,
				'three'  =>  $threeHeader,
		);
	}
	
	public static function channelSumData($params){
		$list = ModComplex::channelSumData($params);

		$special_id = $params['special_id'];
		if($params['time_start'] == $params['time_end']){
			$date = $params['time_start'];
		}else{
			$date = date('Y.m.d', strtotime($params['time_start'])).'~'.date('Y.m.d', strtotime($params['time_end']));
		}
		
		$result = array();
		$result_one = $result_two = $result_three = array();
		
		$modSpecialChannel = new ModSpecialChannel();
		$game = PubBase::getCurrentGame();
		$speChannList = $modSpecialChannel->channelForSpecialIdAll($game);
		$special_c = $s_c_name_array = $c_name_array = array();
		foreach ($speChannList as $key=>$val){
			$special_c[$val['special_id']][] = $val['tab'];
			$s_c_name_array[$val['special_id']] = $val['special_name'];
			$c_name_array[$val['tab']] = $val['channel_name'];
		}
		
		foreach ($list as $key=>$val){
			$result_one[$special_id]['RecDate'] = $date;
			$result_one[$special_id]['Special'] = '全部';
			$result_one[$special_id]['RegUser'] += $val['RegUser'];
			$result_one[$special_id]['CumRegUser'] += $val['CumRegUser'];
			$result_one[$special_id]['RoleUser'] += $val['RoleUser'];
			$result_one[$special_id]['CumRoleUser'] += $val['CumRoleUser'];
			$result_one[$special_id]['LoginUser'] += $val['LoginUser'];
			$result_one[$special_id]['OldUser'] += $val['OldUser'];
			$result_one[$special_id]['LoginCount'] += $val['LoginCount']; 
			$result_one[$special_id]['MaxOnline'] += $val['MaxOnline'];
			$result_one[$special_id]['AvgOnlineTime'] += $val['AvgOnlineTime'];
			$result_one[$special_id]['AvgPeakUser'] += $val['AvgPeakUser'];
			$result_one[$special_id]['PayUser'] += $val['PayUser'];
			$result_one[$special_id]['PayCount'] += $val['PayCount'];
			$result_one[$special_id]['PayMoney'] += $val['PayMoney'];
			$result_one[$special_id]['PayGold'] += $val['PayGold'];
			$result_one[$special_id]['UsedGold'] += $val['UsedGold'];
			$result_one[$special_id]['FirstPayUser'] += $val['FirstPayUser'];
			$result_one[$special_id]['FirstPayCount'] += $val['FirstPayCount'];
			$result_one[$special_id]['FirstPayMoney'] += $val['FirstPayMoney'];
			$result_one[$special_id]['FirstPayGold'] += $val['FirstPayGold'];
			$result_one[$special_id]['LogoutUser'] += $val['LogoutUser'];
			$result_one[$special_id]['PresentGold'] += $val['PresentGold'];
			$result_one[$special_id]['DAU'] += $val['DAU'];
			$result_one[$special_id]['num'] += 1;
			
			foreach ($special_c as $sk=>$sv){
				$special_two_id = $sk;
				$result_two[$special_two_id]['RecDate'] = $date;
				$result_two[$special_two_id]['Special'] = $s_c_name_array[$special_two_id];
				if(in_array($val['Platform'], $sv)){
					$result_two[$special_two_id]['RegUser'] += $val['RegUser'];
					$result_two[$special_two_id]['CumRegUser'] += $val['CumRegUser'];
					$result_two[$special_two_id]['RoleUser'] += $val['RoleUser'];
					$result_two[$special_two_id]['CumRoleUser'] += $val['CumRoleUser'];
					$result_two[$special_two_id]['LoginUser'] += $val['LoginUser'];
					$result_two[$special_two_id]['OldUser'] += $val['OldUser'];
					$result_two[$special_two_id]['LoginCount'] += $val['LoginCount'];
					$result_two[$special_two_id]['MaxOnline'] += $val['MaxOnline'];
					$result_two[$special_two_id]['AvgOnlineTime'] += $val['AvgOnlineTime'];
					$result_two[$special_two_id]['AvgPeakUser'] += $val['AvgPeakUser'];
					$result_two[$special_two_id]['PayUser'] += $val['PayUser'];
					$result_two[$special_two_id]['PayCount'] += $val['PayCount'];
					$result_two[$special_two_id]['PayMoney'] += $val['PayMoney'];
					$result_two[$special_two_id]['PayGold'] += $val['PayGold'];
					$result_two[$special_two_id]['UsedGold'] += $val['UsedGold'];
					$result_two[$special_two_id]['FirstPayUser'] += $val['FirstPayUser'];
					$result_two[$special_two_id]['FirstPayCount'] += $val['FirstPayCount'];
					$result_two[$special_two_id]['FirstPayMoney'] += $val['FirstPayMoney'];
					$result_two[$special_two_id]['FirstPayGold'] += $val['FirstPayGold'];
					$result_two[$special_two_id]['LogoutUser'] += $val['LogoutUser'];
					$result_two[$special_two_id]['PresentGold'] += $val['PresentGold'];
					$result_two[$special_two_id]['DAU'] += $val['DAU'];
					$result_two[$special_two_id]['num'] += 1;
				}
				
				foreach ($sv as $tk=>$tv){
					if($params['special_id'] != 'ALL' && $params['special_id'] != $sk){  //如果选择了专服，只显示该专服下的渠道数据
						continue;
					}
					$special_three_id = $sk.'-'.$tv;
					$result_three[$special_three_id]['RecDate'] = $date;
					$result_three[$special_three_id]['Special'] = $s_c_name_array[$sk];
					$result_three[$special_three_id]['Channel'] = $c_name_array[$tv];
					if($val['Platform'] == $tv){
						$result_three[$special_three_id]['RegUser'] += $val['RegUser'];
						$result_three[$special_three_id]['CumRegUser'] += $val['CumRegUser'];
						$result_three[$special_three_id]['RoleUser'] += $val['RoleUser'];
						$result_three[$special_three_id]['CumRoleUser'] += $val['CumRoleUser'];
						$result_three[$special_three_id]['LoginUser'] += $val['LoginUser'];
						$result_three[$special_three_id]['OldUser'] += $val['OldUser'];
						$result_three[$special_three_id]['LoginCount'] += $val['LoginCount'];
						$result_three[$special_three_id]['MaxOnline'] += $val['MaxOnline'];
						$result_three[$special_three_id]['AvgOnlineTime'] += $val['AvgOnlineTime'];
						$result_three[$special_three_id]['AvgPeakUser'] += $val['AvgPeakUser'];
						$result_three[$special_three_id]['PayUser'] += $val['PayUser'];
						$result_three[$special_three_id]['PayCount'] += $val['PayCount'];
						$result_three[$special_three_id]['PayMoney'] += $val['PayMoney'];
						$result_three[$special_three_id]['PayGold'] += $val['PayGold'];
						$result_three[$special_three_id]['UsedGold'] += $val['UsedGold'];
						$result_three[$special_three_id]['FirstPayUser'] += $val['FirstPayUser'];
						$result_three[$special_three_id]['FirstPayCount'] += $val['FirstPayCount'];
						$result_three[$special_three_id]['FirstPayMoney'] += $val['FirstPayMoney'];
						$result_three[$special_three_id]['FirstPayGold'] += $val['FirstPayGold'];
						$result_three[$special_three_id]['LogoutUser'] += $val['LogoutUser'];
						$result_three[$special_three_id]['PresentGold'] += $val['PresentGold'];
						$result_three[$special_three_id]['DAU'] += $val['DAU'];
						$result_three[$special_three_id]['num'] += 1;
					}
				}
			}
			
		}

		
		foreach($result_one as &$v){
			$v['arppu'] = $v['PayUser'] == 0? 0 : number_format($v['PayMoney'] / $v['PayUser'],2);
			$v['loginArppu'] = $v['LoginUser'] == 0? '0.00%' : number_format($v['PayUser'] / $v['LoginUser'] * 100, 2, '.', '')."%";
			$v['addPayArppu'] = $v['RoleUser'] ==0? '0.00%' : number_format($v['FirstPayUser'] / $v['RoleUser'] * 100, 2, '.', '')."%";
			$v['addArppu'] = $v['FirstPayUser'] == 0? 0 : number_format($v['FirstPayMoney'] / $v['FirstPayUser'],2);
		
			$v['AvgOnlineTime'] = $v['AvgOnlineTime'] / $v['num'];
			$v['AvgPeakUser'] = $v['AvgPeakUser'] / $v['num'];
			
			$v['RegUser'] = isset($v['RegUser'])? $v['RegUser'] : 0;
			$v['RoleUser'] = isset($v['RoleUser'])? $v['RoleUser'] : 0;
			$v['DAU'] = isset($v['DAU'])? $v['DAU'] : 0;
			$v['LoginUser'] = isset($v['LoginUser'])? $v['LoginUser'] : 0;
			$v['LogoutUser'] = isset($v['LogoutUser'])? $v['LogoutUser'] : 0;
			$v['OldUser'] = isset($v['OldUser'])? $v['OldUser'] : 0;
			$v['LoginCount'] = isset($v['LoginCount'])? $v['LoginCount'] : 0;
			$v['PayUser'] = isset($v['PayUser'])? $v['PayUser'] : 0;
			$v['PayMoney'] = isset($v['PayMoney'])? $v['PayMoney'] : 0;
			$v['PayCount'] = isset($v['PayCount'])? $v['PayCount'] : 0;
			$v['PayGold'] = isset($v['PayGold'])? $v['PayGold'] : 0;
			$v['PresentGold'] = isset($v['PresentGold'])? $v['PresentGold'] : 0;
			$v['UsedGold'] = isset($v['UsedGold'])? $v['UsedGold'] : 0;
			
			$v['FirstPayUser'] = isset($v['FirstPayUser'])? $v['FirstPayUser'] : 0;
			$v['FirstPayCount'] = isset($v['FirstPayCount'])? $v['FirstPayCount'] : 0;
			$v['FirstPayMoney'] = isset($v['FirstPayMoney'])? $v['FirstPayMoney'] : 0;
			$v['FirstPayGold'] = isset($v['FirstPayGold'])? $v['FirstPayGold'] : 0;
			
			$v['CumRegUser'] = isset($v['CumRegUser'])? $v['CumRegUser'] : 0;
			$v['CumRoleUser'] = isset($v['CumRoleUser'])? $v['CumRoleUser'] : 0;
		}
		unset($v);
		
		foreach($result_two as &$v){
			$v['arppu'] = $v['PayUser'] == 0? 0 : number_format($v['PayMoney'] / $v['PayUser'],2);
			$v['loginArppu'] = $v['LoginUser'] == 0? '0.00%' : number_format($v['PayUser'] / $v['LoginUser'] * 100, 2, '.', '')."%";
			$v['addPayArppu'] = $v['RoleUser'] ==0? '0.00%' : number_format($v['FirstPayUser'] / $v['RoleUser'] * 100, 2, '.', '')."%";
			$v['addArppu'] = $v['FirstPayUser'] == 0? 0 : number_format($v['FirstPayMoney'] / $v['FirstPayUser'],2);
		
			$v['AvgOnlineTime'] = $v['AvgOnlineTime'] / $v['num'];
			$v['AvgPeakUser'] = $v['AvgPeakUser'] / $v['num'];
			
			$v['RegUser'] = isset($v['RegUser'])? $v['RegUser'] : 0;
			$v['RoleUser'] = isset($v['RoleUser'])? $v['RoleUser'] : 0;
			$v['DAU'] = isset($v['DAU'])? $v['DAU'] : 0;
			$v['LoginUser'] = isset($v['LoginUser'])? $v['LoginUser'] : 0;
			$v['LogoutUser'] = isset($v['LogoutUser'])? $v['LogoutUser'] : 0;
			$v['OldUser'] = isset($v['OldUser'])? $v['OldUser'] : 0;
			$v['LoginCount'] = isset($v['LoginCount'])? $v['LoginCount'] : 0;
			$v['PayUser'] = isset($v['PayUser'])? $v['PayUser'] : 0;
			$v['PayMoney'] = isset($v['PayMoney'])? $v['PayMoney'] : 0;
			$v['PayCount'] = isset($v['PayCount'])? $v['PayCount'] : 0;
			$v['PayGold'] = isset($v['PayGold'])? $v['PayGold'] : 0;
			$v['PresentGold'] = isset($v['PresentGold'])? $v['PresentGold'] : 0;
			$v['UsedGold'] = isset($v['UsedGold'])? $v['UsedGold'] : 0;

			$v['FirstPayUser'] = isset($v['FirstPayUser'])? $v['FirstPayUser'] : 0;
			$v['FirstPayCount'] = isset($v['FirstPayCount'])? $v['FirstPayCount'] : 0;
			$v['FirstPayMoney'] = isset($v['FirstPayMoney'])? $v['FirstPayMoney'] : 0;
			$v['FirstPayGold'] = isset($v['FirstPayGold'])? $v['FirstPayGold'] : 0;
				
			$v['CumRegUser'] = isset($v['CumRegUser'])? $v['CumRegUser'] : 0;
			$v['CumRoleUser'] = isset($v['CumRoleUser'])? $v['CumRoleUser'] : 0;
		}
		unset($v);
		
		foreach($result_three as &$v){
			$v['arppu'] = $v['PayUser'] == 0? 0 : number_format($v['PayMoney'] / $v['PayUser'],2);
			$v['loginArppu'] = $v['LoginUser'] == 0? '0.00%' : number_format($v['PayUser'] / $v['LoginUser'] * 100, 2, '.', '')."%";
			$v['addPayArppu'] = $v['RoleUser'] ==0? '0.00%' : number_format($v['FirstPayUser'] / $v['RoleUser'] * 100, 2, '.', '')."%";
			$v['addArppu'] = $v['FirstPayUser'] == 0? 0 : number_format($v['FirstPayMoney'] / $v['FirstPayUser'],2);
		
			$v['AvgOnlineTime'] = $v['AvgOnlineTime'] / $v['num'];
			$v['AvgPeakUser'] = $v['AvgPeakUser'] / $v['num'];
			
			$v['RegUser'] = isset($v['RegUser'])? $v['RegUser'] : 0;
			$v['RoleUser'] = isset($v['RoleUser'])? $v['RoleUser'] : 0;
			$v['DAU'] = isset($v['DAU'])? $v['DAU'] : 0;
			$v['LoginUser'] = isset($v['LoginUser'])? $v['LoginUser'] : 0;
			$v['LogoutUser'] = isset($v['LogoutUser'])? $v['LogoutUser'] : 0;
			$v['OldUser'] = isset($v['OldUser'])? $v['OldUser'] : 0;
			$v['LoginCount'] = isset($v['LoginCount'])? $v['LoginCount'] : 0;
			$v['PayUser'] = isset($v['PayUser'])? $v['PayUser'] : 0;
			$v['PayMoney'] = isset($v['PayMoney'])? $v['PayMoney'] : 0;
			$v['PayCount'] = isset($v['PayCount'])? $v['PayCount'] : 0;
			$v['PayGold'] = isset($v['PayGold'])? $v['PayGold'] : 0;
			$v['PresentGold'] = isset($v['PresentGold'])? $v['PresentGold'] : 0;
			$v['UsedGold'] = isset($v['UsedGold'])? $v['UsedGold'] : 0;

			$v['FirstPayUser'] = isset($v['FirstPayUser'])? $v['FirstPayUser'] : 0;
			$v['FirstPayCount'] = isset($v['FirstPayCount'])? $v['FirstPayCount'] : 0;
			$v['FirstPayMoney'] = isset($v['FirstPayMoney'])? $v['FirstPayMoney'] : 0;
			$v['FirstPayGold'] = isset($v['FirstPayGold'])? $v['FirstPayGold'] : 0;
				
			$v['CumRegUser'] = isset($v['CumRegUser'])? $v['CumRegUser'] : 0;
			$v['CumRoleUser'] = isset($v['CumRoleUser'])? $v['CumRoleUser'] : 0;
		}
		unset($v);
		
		$result['one'] = $result_one;
		$result['two'] = $result_two;
		$result['three'] = $result_three;
		
		return $result;
		
	}

    public static function indexHeader($params){
        $header = array(
            'RecDate'   => array('text' => '日期'),
            'SID'       => array('text' => '服'),
            'MainData'  => array('text' => '核心数据', 'include' => array(
                'RegUser'       => array('text' => '新注册账号数', 'rule' => 'numeric'),
                'RoleUser'      => array('text' => '创角数', 'rule' => 'numeric'),
                'DAU'           => array('text' => '活跃人数', 'rule' => 'numeric'),
                'LoginUser'     => array('text' => '登入人数', 'rule' => 'numeric'),
                'LogoutUser'    => array('text' => '登出人数', 'rule' => 'numeric'),
                'OldUser'       => array('text' => '老用户数', 'rule' => 'numeric'),
                'LoginCount'    => array('text' => '登录次数', 'rule' => 'numeric'),
                'PayUser'       => array('text' => '充值玩家数', 'rule' => 'numeric'),
                'PayMoney'      => array('text' => '充值收入', 'rule' => 'numeric'),
                'PayCount'      => array('text' => '充值次数', 'rule' => 'numeric'),
                'PayGold'       => array('text' => '充值所得元宝数', 'rule' => 'numeric'),
                'PresentGold'   => array('text' => '充值赠送元宝数', 'rule' => 'numeric'),
                'UsedGold'      => array('text' => '消耗虚拟货币数', 'rule' => 'numeric'),
                'MaxOnline'     => array('text' => '在线峰值', 'rule' => 'numeric'),
                'AvgOnlineTime' => array('text' => '平均在线时长(秒)', 'rule' => 'numeric'),
                'AvgPeakUser'   => array('text' => '平均在线峰值', 'rule' => 'numeric'),
            )),
            'FirstData'     => array('text' => '首充数据', 'include' => array(
                'FirstPayUser'  => array('text' => '首充玩家数', 'rule' => 'numeric'),
                'FirstPayCount' => array('text' => '首充订单数', 'rule' => 'numeric'),
                'FirstPayMoney' => array('text' => '首充金额', 'rule' => 'numeric'),
                'FirstPayGold'  => array('text' => '首充元宝数', 'rule' => 'numeric'),
            )),
            'CumData'       => array('text' => '累计数据', 'include' => array(
                'CumRegUser'    => array('text' => '累计注册账号', 'rule' => 'numeric'),
                'CumRoleUser'   => array('text' => '累计创角数', 'rule' => 'numeric'),
            )),
            'RemainData'    => array('text' => '注册用户留存', 'include' => array(
                'Remain1Day'    => array('text' => '次日'),
            	'Remain2Day'    => array('text' => '2日'),
                'Remain3Day'    => array('text' => '3日'),
            	'Remain4Day'    => array('text' => '4日'),
            	'Remain5Day'    => array('text' => '5日'),
            	'Remain6Day'    => array('text' => '6日'),
                'Remain7Day'    => array('text' => '7日'),
                'Remain14Day'   => array('text' => '14日'),
                'Remain30Day'   => array('text' => '30日'),
                'Remain60Day'   => array('text' => '60日'),
                'Remain90Day'   => array('text' => '90日'),
            )),
        	'MainArppu' => array('text' => '付费率', 'include' => array(
        			'arppu' => array('text' => 'arppu'),
        			'loginArppu' => array('text' => '登录付费率'),
//         			'addPayCount' => array('text' => '新增付费人数'),
//         			'addPayMoney' => array('text' => '新增账号充值'),
        			'addPayArppu' => array('text' => '新增付费率'),
        			'addArppu' => array('text' => '新增arppu'),
        	))
        );
        if($params['server'] == 'ALL'){
        	unset($header['SID']);
        }
        return $header;
    }

    public static function indexData($params){
        if(PubFunc::checkEmpty($params, array('g', 'period'))) return array();

        $data = ModComplex::indexData($params);
       
        $new_data = array();
        $day = array(1,2,3,4,5,6,7,14,30,60,90);
        foreach ($data as $key=>$val){
        	if($params['server'] != 'ALL'){
        		$new_data[$val['RecDate']]['SID'] = $val['SID'];
        	}
        	$new_data[$val['RecDate']]['RecDate'] = $val['RecDate'];
        	
        	$new_data[$val['RecDate']]['RegUser'] += $val['RegUser'];
        	$new_data[$val['RecDate']]['CumRegUser'] += $val['CumRegUser'];
        	$new_data[$val['RecDate']]['RoleUser'] += $val['RoleUser'];
        	$new_data[$val['RecDate']]['CumRoleUser'] += $val['CumRoleUser'];
        	$new_data[$val['RecDate']]['LoginUser'] += $val['LoginUser'];
        	$new_data[$val['RecDate']]['OldUser'] += $val['OldUser'];
        	$new_data[$val['RecDate']]['LoginCount'] += $val['LoginCount'];
        	
        	$new_data[$val['RecDate']]['MaxOnline'] += $val['MaxOnline'];
        	$new_data[$val['RecDate']]['AvgOnlineTime'] += $val['AvgOnlineTime'];
        	$new_data[$val['RecDate']]['AvgPeakUser'] += $val['AvgPeakUser'];
        	$new_data[$val['RecDate']]['num'] += 1;
        	
        	
        	$new_data[$val['RecDate']]['PayUser'] += $val['PayUser'];
        	$new_data[$val['RecDate']]['PayCount'] += $val['PayCount'];
        	$new_data[$val['RecDate']]['PayMoney'] += $val['PayMoney'];
        	$new_data[$val['RecDate']]['PayGold'] += $val['PayGold'];
        	$new_data[$val['RecDate']]['UsedGold'] += $val['UsedGold'];
        	$new_data[$val['RecDate']]['FirstPayUser'] += $val['FirstPayUser'];
        	$new_data[$val['RecDate']]['FirstPayCount'] += $val['FirstPayCount'];
        	$new_data[$val['RecDate']]['FirstPayMoney'] += $val['FirstPayMoney'];
        	$new_data[$val['RecDate']]['FirstPayGold'] += $val['FirstPayGold'];
        	$new_data[$val['RecDate']]['LogoutUser'] += $val['LogoutUser'];
        	$new_data[$val['RecDate']]['PresentGold'] += $val['PresentGold'];
        	$new_data[$val['RecDate']]['DAU'] += $val['DAU'];
        
        	 
        	foreach ($day as $k=>$v){
        		$new_data[$val['RecDate']]['Remain'.$v.'Day'] += $val['Remain'.$v.'Day'];
        	}
        }

        
        foreach($new_data as &$v){
            $v['UsedCoin'] = number_format(abs($v['UsedCoin']), 0, '.', ',');
            foreach ($day as $key=>$val){
            	if(!empty($v['Remain'.$val.'Day'])){
            		$v['Remain'.$val.'Day'] = "{$v['Remain'.$val.'Day']}(<span style='color:green;'>".number_format($v['Remain'.$val.'Day'] / $v['RegUser'] * 100, 2, '.', '')."%</span>)";
            	}
            }
            
            $v['arppu'] = $v['PayUser'] == 0? 0 : number_format($v['PayMoney'] / $v['PayUser'],2);
            $v['loginArppu'] = $v['LoginUser'] == 0? '0.00%' : number_format($v['PayUser'] / $v['LoginUser'] * 100, 2, '.', '')."%";
            $v['addPayArppu'] = $v['RoleUser'] ==0? '0.00%' : number_format($v['FirstPayUser'] / $v['RoleUser'] * 100, 2, '.', '')."%";
            $v['addArppu'] = $v['FirstPayUser'] == 0? 0 : number_format($v['FirstPayMoney'] / $v['FirstPayUser'],2);

            $v['AvgOnlineTime'] = $v['AvgOnlineTime'] / $v['num'];
            $v['AvgPeakUser'] = $v['AvgPeakUser'] / $v['num'];
        }
        unset($v);

        return $new_data;
    }

    public static function indexChart($data, $params){
        $chartData = array();

        foreach($data as $v){
            $chartData['注册用户'][$v['RecDate']] = intval($v['RegUser']);
            $chartData['活跃用户'][$v['RecDate']] = intval($v['LoginUser']);
        }

        return array(
            'title'  => '用户数',
            'data'   => $chartData,
            'config' => array(
                'yAxis'  => array(
                    array(
                        'name' => '活跃用户',
                    ),
                    array(
                        'name' => '注册用户',
                    )
                ),
                'series' => array(

                    '注册用户' => array(
                        'yAxisIndex' => 1,
                    ),
                    '活跃用户' => array(
                        'markPoint' => array(
                            'data' => array(
                                array('type' => 'max','name' => PubFunc::t('最大值')),
                                array('type' => 'min','name' => PubFunc::t('最小值'))
                            )
                        )
                    ),
                )
            )
        );
    }
    
    
    
    
    public static function uniforms_header($params){
    	$header = array(
    			'server'  => array('text' => '服务器'),
    			'ctime'       => array('text' => '日期'),
    			'zd1'       => array('text' => '当天注册数'),
    			'zd2'       => array('text' => '当天创角数'),
    			'zd3'       => array('text' => '当天登录数'),
    			'zd4'       => array('text' => '当天活跃数'),
    			'zd5'       => array('text' => '老玩家'),
    			'zd6'       => array('text' => '付费数'),
    			'zd7'       => array('text' => '充值数'),
    			'zd8'       => array('text' => '登录付费数'),
    			'zd9'       => array('text' => '付费arpu'),
    			'zd10'       => array('text' => '新付费数'),
    			'zd11'       => array('text' => '新充值数'),
    			'zd12'       => array('text' => '新付费率'),
    			'zd13'       => array('text' => '新付费ARPU'),
    			'zd14'       => array('text' => '老付费人数'),
    			'zd15'       => array('text' => '老付费率'),
    			'zd16'       => array('text' => '老ARPU'),
    			'zd17'       => array('text' => '注册ARPU'),
    			
    	);
    	return $header;
    }
    
    
    public static function channel_header($params){
    	$header = array(
    			'server'  => array('text' => '渠道'),
    			'ctime'       => array('text' => '日期'),
    			'zd1'       => array('text' => '当天注册数'),
    			'zd2'       => array('text' => '当天创角数'),
    			'zd3'       => array('text' => '当天登录数'),
    			'zd4'       => array('text' => '当天活跃数'),
    			'zd5'       => array('text' => '老玩家'),
    			'zd6'       => array('text' => '付费数'),
    			'zd7'       => array('text' => '充值数'),
    			'zd8'       => array('text' => '登录付费数'),
    			'zd9'       => array('text' => '付费arpu'),
    			'zd10'       => array('text' => '新付费数'),
    			'zd11'       => array('text' => '新充值数'),
    			'zd12'       => array('text' => '新付费率'),
    			'zd13'       => array('text' => '新付费ARPU'),
    			'zd14'       => array('text' => '老付费人数'),
    			'zd15'       => array('text' => '老付费率'),
    			'zd16'       => array('text' => '老ARPU'),
    			'zd17'       => array('text' => '注册ARPU'),
    			 
    	);
    	return $header;
    }
    
    
    
} 